package com.xxd.spring.boot.demo.lihonghai.Eeception;

import com.xxd.spring.boot.demo.lihonghai.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class MyExceptionHandler {
    @ExceptionHandler(value=MyException.class)
    @ResponseBody
    public Result exceptionHandler(MyException e){
        System.out.println("未知异常！原因是:"+e.getMassage());
        Result result=new Result();
        result.setCode(e.getCode());
        result.setMessage(e.getMassage());
        return result;
    }
}
